package com.xydtech.ecard.merchant.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.domain.entity.SysDept;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.merchant.domain.EcardBranchVisitInfo;
import com.xydtech.ecard.merchant.service.IEcardBranchVisitInfoService;
import com.xydtech.system.service.ISysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 企业拜访统计Controller
 *
 * @author yuzhiguo
 * @date 2024-09-11 上午8:41
 */
@Controller
@RequestMapping("/merchant/branchEntVisitInfo")
public class EcardBranchEnterpriseVisitInfoController extends BaseController {

    @Autowired
    private IEcardBranchVisitInfoService ecardBranchVisitInfoService;
    @Autowired
    private ISysDeptService sysDeptService;

    private String prefix = "merchant";

    @RequiresPermissions("merchant:branchEntVisitInfo:view")
    @GetMapping()
    public String merchant()
    {
        return prefix + "/branchEnterpriseVisitInfo";
    }

    @RequiresPermissions("merchant:branchEntVisitInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardBranchVisitInfo ecardBranchVisitInfo) {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        ecardBranchVisitInfo.setDictDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchVisitInfo> list = ecardBranchVisitInfoService.selectBranchEnterpriseVisitInfoList(ecardBranchVisitInfo);
        return getDataTable(list);
    }

    @RequiresPermissions("merchant:branchEntVisitInfo:export")
    @Log(title = "导出企业拜访统计信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardBranchVisitInfo ecardBranchVisitInfo)
    {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        ecardBranchVisitInfo.setDictDeptId(sysDept.getDeptId());
        List<EcardBranchVisitInfo> list = ecardBranchVisitInfoService.selectBranchEnterpriseVisitInfoList(ecardBranchVisitInfo);
        ExcelUtil<EcardBranchVisitInfo> util = new ExcelUtil<EcardBranchVisitInfo>(EcardBranchVisitInfo.class);
        return util.exportExcel(list, "企业拜访统计");
    }
}
